package com.example.demo;

import com.alibaba.excel.EasyExcel;

import java.util.ArrayList;
import java.util.List;

public class WriteExcelDemo {

    private static List<Student> data() {
        List<Student> list = new ArrayList<Student>();
        for (int i = 0; i < 10; i++) {
            Student data = new Student();
            data.setSno(i);
            data.setSname("张三"+i);
            list.add(data);
        }
        return list;
    }

    // 方式一：
    public static void main(String[] args) throws Exception {
        String fileName = "D:\\1.xlsx";
        // 参数1：文件路径，参数2：实体类class
        EasyExcel.write(fileName, Student.class)
                // 参数1：sheetName
                .sheet("sheet名1")
                // List数据
                .doWrite(data());
    }
}
